using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;

using Microsoft.SqlServer.Management.Common;
using System.Collections;

namespace Quanly_dethi.Class
{
    class csC_Cauhoi
    {
        private ketnoi kn;

        public ketnoi Kn
        {
            get { return kn; }
            set { kn = value; }
        }
        private string databasename;

        public string Databasename
        {
            get { return databasename; }
            set { databasename = value; }
        }
        public csC_Cauhoi()
        {
            Kn = new ketnoi();
            databasename = "";
        }
        public csC_Cauhoi(string servername, string user, string pass, string dbname)
        {
            Kn = new ketnoi(servername ,user, pass);
            databasename = dbname;
        }
        public DataTable Sellect()
        { 
            Database db=Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select * from CauHoi where Xoa='0'").Tables[0];
        }
        public DataTable Sellect_Mch()
        {

            Database db = Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select top 1 MaCH from CauHoi where Xoa='0' order by MaCH DESC").Tables[0];
        }
        public void Update(csE_Cauhoi x)
        {
            string t = "update CauHoi set Noidung=N'" + x.Noidung + "', MaTD='" + x.Matd + "', MaDK='" + x.Madk + "', Xoa='0' where MaCH='" + x.Mach + "'";
            Database db=Kn._Server.Databases[databasename];
            db.ExecuteWithResults(t);

        }
        public void insert(csE_Cauhoi x)
        {
            Database db = Kn._Server.Databases[databasename];
            string s = "insert into CauHoi(Noidung, MaTD, MaDK, Xoa) values('" + x.Noidung.ToString() + "','" + int.Parse(x.Matd.ToString()) + "','" + int.Parse(x.Madk.ToString()) + "','"+ int.Parse(x.Xoa.ToString())+"')";
            
            db.ExecuteWithResults(s);

        }
       
    }
}
